package controller

import (
	"gg_server/websocket"

	"github.com/gin-gonic/gin"
)

// websocket

type Websocket struct{}

var WebsocketController *Websocket

func init() {
	WebsocketController = &Websocket{}
}

// 升级协议
func (w *Websocket) Upgrader(ctx *gin.Context) {
	// 与客户端协商子协议
	token := ctx.Request.Header.Get("Sec-WebSocket-Protocol")
	ctx.Header("Sec-WebSocket-Protocol", token)

	// 升级协议
	websocket.CreateWS().HandleRequest(ctx.Writer, ctx.Request)
}
